﻿// ----------------------------------------------------------------------
// <copyright file="HtmlParser.cs" company="Axitech">
//     Copyright (c) Axitech. All rights reserved.
// </copyright>
// <author>Anton Prilepskiy</author>
// <email>a.prilepskiy@axitech.ru</email>
// <cvs>$Id$</cvs>
// ----------------------------------------------------------------------

namespace Axitech.PlaylistCreator
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using Axitech.PlaylistCreator.Playlist;

    /// <summary>
    /// HTML Parser class
    /// </summary>
    public static class HtmlParser
    {
        private static String mPattern1 = @"<!--spoiler_title-->(?<title>[^\<]+)<!--spoiler_title_end-->.*<!--dle_video_begin:(?<url>[^\>]+)-->";

        /// <summary>
        /// Method for parsing animejapan.ru html page
        /// </summary>
        /// <returns>M3U playlist content</returns>
        public static String Parse(String html)
        {
            var builder = new PlaylistBuilder();

            foreach(Match m in Regex.Matches(html, mPattern1))
            {
                if (m.Success)
                {
                    builder.Elements.Add(new PlaylistElement()
                    {
                        Title = m.Groups["title"].Value,
                        Url = m.Groups["url"].Value
                    });
                }
            }

            return builder.GetPlaylist();
        }
    }
}
